package com.iknow.share;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.util.StringUtil;
import com.weibo.net.AccessToken;
import com.weibo.net.AsyncWeiboRunner;
import com.weibo.net.AsyncWeiboRunner.RequestListener;
import com.weibo.net.RequestToken;
import com.weibo.net.Weibo;
import com.weibo.net.WeiboException;
import com.weibo.net.WeiboParameters;
import java.io.IOException;
import java.net.MalformedURLException;

public class SinaWeibo
  implements ShareHandler, AsyncWeiboRunner.RequestListener
{
  public static final String CONSUMER_KEY = "2832649083";
  public static final String CONSUMER_SECRET = "191a6c08a5d3f783a5bd0de5accd180b";
  public static final String EXTAR_OAUTH_VERIFIER = "oauth_verifier";
  public static final String EXTRA_ACCESS_TOKEN = "com.weibo.android.accesstoken";
  public static final String EXTRA_PIC_URI = "com.weibo.android.pic.uri";
  public static final String EXTRA_TOKEN_SECRET = "com.weibo.android.token.secret";
  public static final String EXTRA_WEIBO_CONTENT = "com.weibo.android.content";
  public static final String URL_ACTIVITY_CALLBACK = "weiboandroidsdk://com.weibo.net.ShareActivity";
  public static final int WEIBO_MAX_LENGTH = 140;
  public final String FROM = "weibo";
  private String mAccessToken = "";
  private Context mContext;
  private String mTokenSecret = "";
  Weibo mWeibo = Weibo.getInstance();
  private RequestToken requestToken = null;

  private String updateWeibo(Weibo paramWeibo, String paramString1, String paramString2, String paramString3, String paramString4)
    throws MalformedURLException, IOException, WeiboException
  {
    WeiboParameters localWeiboParameters = new WeiboParameters();
    localWeiboParameters.add("source", paramString1);
    localWeiboParameters.add("status", paramString2);
    if (!(TextUtils.isEmpty(paramString3)))
      localWeiboParameters.add("lon", paramString3);
    if (!(TextUtils.isEmpty(paramString4)))
      localWeiboParameters.add("lat", paramString4);
    String str = Weibo.SERVER + "statuses/update.json";
    new AsyncWeiboRunner(paramWeibo).request(this.mContext, str, localWeiboParameters, "POST", this);
    return "";
  }

  private String uploadWeibo(Weibo paramWeibo, String paramString1, String paramString2, String paramString3, String paramString4, String paramString5)
    throws WeiboException
  {
    String str1 = IKnow.mProfileImageCacheManager.getImageManager().getLocalImagePath(paramString2);
    WeiboParameters localWeiboParameters = new WeiboParameters();
    localWeiboParameters.add("source", paramString1);
    localWeiboParameters.add("pic", str1);
    localWeiboParameters.add("status", paramString3);
    if (!(TextUtils.isEmpty(paramString4)))
      localWeiboParameters.add("lon", paramString4);
    if (!(TextUtils.isEmpty(paramString5)))
      localWeiboParameters.add("lat", paramString5);
    String str2 = Weibo.SERVER + "statuses/upload.json";
    new AsyncWeiboRunner(paramWeibo).request(this.mContext, str2, localWeiboParameters, "POST", this);
    return "";
  }

  public String getAuthenticationUrl(Context paramContext)
  {
    String str1;
    this.mWeibo.setupConsumerConfig("2832649083", "191a6c08a5d3f783a5bd0de5accd180b");
    try
    {
      this.mContext = paramContext;
      this.requestToken = this.mWeibo.getRequestToken(paramContext, Weibo.APP_KEY, Weibo.APP_SECRET, "weiboandroidsdk://com.weibo.net.ShareActivity");
      String str2 = Uri.parse(Weibo.URL_AUTHENTICATION + "?display=wap1.0&oauth_token=" + this.requestToken.getToken() + "&from=" + "weibo").toString();
      str1 = str2;
      return str1;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      str1 = null;
    }
  }

  public int getMaxTextCount()
  {
    return 140;
  }

  public boolean isAuthenticated()
  {
    int i = 0;
    if (!(StringUtil.isEmpty(IKnow.mSystemConfig.getString("com.weibo.android.accesstoken"))))
      i = 1;
    return i;
  }

  public void onComplete(String paramString)
  {
  }

  public void onError(WeiboException paramWeiboException)
  {
  }

  public void onIOException(IOException paramIOException)
  {
  }

  public void onUriCompleteEvent(Uri paramUri, Context paramContext)
  {
    String str;
    this.mAccessToken = IKnow.mSystemConfig.getString("com.weibo.android.accesstoken");
    this.mTokenSecret = IKnow.mSystemConfig.getString("com.weibo.android.token.secret");
    if ((!("".equals(this.mAccessToken))) || (!("".equals(this.mTokenSecret))))
    {
      AccessToken localAccessToken = new AccessToken(this.mAccessToken, this.mTokenSecret);
      this.mWeibo.setAccessToken(localAccessToken);
    }
    do
    {
      return;
      str = paramUri.getQueryParameter("oauth_verifier");
    }
    while (str == null);
    this.mWeibo.addOauthverifier(str);
    try
    {
      this.mWeibo.generateAccessToken(paramContext, null);
      IKnow.mSystemConfig.setString("com.weibo.android.accesstoken", this.mWeibo.getAccessToken().getToken());
      IKnow.mSystemConfig.setString("com.weibo.android.token.secret", this.mWeibo.getAccessToken().getSecret());
    }
    catch (Exception localException)
    {
    }
  }

  public boolean share(Context paramContext, String paramString1, String paramString2)
  {
    this.mContext = paramContext;
    try
    {
      if (!(StringUtil.isEmpty(paramString2)))
        uploadWeibo(this.mWeibo, Weibo.APP_KEY, paramString2, paramString1, "", "");
      else
        updateWeibo(this.mWeibo, Weibo.APP_KEY, paramString1, "", "");
    }
    catch (WeiboException localWeiboException)
    {
      i = 0;
      break label84:
    }
    catch (MalformedURLException localMalformedURLException)
    {
      while (true)
        localMalformedURLException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      while (true)
        localIOException.printStackTrace();
    }
    int i = 1;
    label84: return i;
  }
}